package com.glsc.ngateway.opmanage.controller.deposit;


import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.deposit.DepositoryBank;
import com.glsc.ngateway.opmanage.aspect.UserCache;
import com.glsc.ngateway.opmanage.dto.DepositoryBankDto;
import com.glsc.ngateway.opmanage.service.deposit.DepositoryBankService;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * 存管银行配置
 */
@RestController
@RequestMapping("/api/depositoryBank")
@Slf4j
public class DepositoryBankController {

    @Resource
    private UserCache userCache;

    @Resource
    private DepositoryBankService depositoryBankService;

    /**
     * 分页查找
     *
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("/page")
    public PlatformResponse<Page<DepositoryBank>> pageTemplate(@RequestBody DepositoryBankDto dto, HttpServletRequest request) {

        Map<String, Object> param = new HashMap<>();
        if (StringUtils.isNotBlank(dto.getBankName())) {
            param.put("LIKE_bankName", dto.getBankName());
        }
        Page<DepositoryBank> page = depositoryBankService.page(dto.getPageNo(), dto.getPageSize(), param);

        return PlatformResponse.successData(page);
    }

    /**
     * 根据id查找
     *
     * @param
     * @return
     */
    @GetMapping("/findById")
    public PlatformResponse<DepositoryBank> findTemplateById(@ApiParam(required = false, value = "id") @RequestParam(required = true) Integer id) {
        return PlatformResponse.successData(depositoryBankService.findById(id));
    }

    /**
     * 保存
     *
     * @param obj
     * @return
     */
    @PostMapping("/save")
    public PlatformResponse<?> saveTemplate(@RequestBody DepositoryBank obj) {
        depositoryBankService.save(obj);
        return PlatformResponse.success();
    }

    /**
     * 根据id删除
     *
     * @param obj
     * @return
     */
    @PostMapping("/delete")
    public PlatformResponse<?> deleteTemplate(@RequestBody DepositoryBank obj) {
        depositoryBankService.delete(obj.getId());
        return PlatformResponse.success();
    }


}
